﻿using ConfExpert.Forms.Base;
using DevTeam;
using System;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class ProductsByDesen : XForm
    {
        public ProductsByDesen()
        {
            InitializeComponent();
        }

        BindingSource bs;
        private void ProductsByDesen_Load(object sender, EventArgs e)
        {
            bs = gridView1.Init("GetProductsByDesen");
            gridView1.AddDetailGrid(gridView2, "Desen,V,C");
            gridView1.AddColumn("LineCount", typeof(int), "COUNT(Child({FK}).ProductId)");
            gridView1.MakeColumnInvisible("V", "C");
            gridView1.MakeReadOnly("KCustomerId", "KVendorId");
            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            gridView2.Columns["ProductId"].Visible = false;     //Scan gizlenmemeli, çünkü Renk alanı var!
            gridView2.Columns["PRO"].Visible = false;     //Scan gizlenmemeli, çünkü Renk alanı var!

            gridView1.AddSummary();
            gridView2.AddSummary();
            gridView1.BestFitColumns();
            gridView2.BestFitColumns();

            btnKaydet.ItemClick += btnKaydet_ItemClick;
            chk2AlaniDolu.CheckedChanged += chk2AlaniDolu_CheckedChanged;
            txtMinAdet.EditValueChanged += txtMinAdet_EditValueChanged;
        }

        void txtMinAdet_EditValueChanged(object sender, EventArgs e)
        {
            Rfrsh();
        }

        void chk2AlaniDolu_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Rfrsh();
        }

        void Rfrsh()
        {
            bs.Filter = "LineCount>=" + txtMinAdet.EditValue.ToInt().ToStr() + (chk2AlaniDolu.Checked ? " AND KCustomerId is not null AND KVendorId is not null" : string.Empty);
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.RefreshDataSource("UpdProductsByDesen", gridView1.SerializeChanges());
            gridView1.BestFitColumns();
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }
    }
}
